<?php

namespace pmvc\ioc;

use pmvc\Properties;
use Exception;

class PropertiesDescriptorPostProcessor
implements DescriptorPostProcessor {

	private $properties = NULL;

	/**
	 * {@inheritDoc}
	 */
	function process(ObjectDescriptor $descriptor) {
		$descriptor->class 			= $this->properties->evalPropertyString($descriptor->class);
		$descriptor->factoryClass 	= $this->properties->evalPropertyString($descriptor->factoryClass);
		$descriptor->singleton 		= $this->properties->evalPropertyString($descriptor->singleton);
		$descriptor->parent 		= $this->properties->evalPropertyString($descriptor->parent);
		$descriptor->abstract 		= $this->properties->evalPropertyString($descriptor->abstract);
		$descriptor->lazy 			= $this->properties->evalPropertyString($descriptor->lazy);
		$descriptor->initMethod 	= $this->properties->evalPropertyString($descriptor->initMethod);
		$descriptor->destroyMethod 	= $this->properties->evalPropertyString($descriptor->destroyMethod);
		foreach ($descriptor->properties as $prop) {
			$this->processProperty($prop);
		}
		foreach ($descriptor->constructorArgs as $arg) {
			$this->processProperty($arg);
		}
	}

	function processProperty(PropertyDescriptor $propDesc) {
		if (is_array($propDesc->value)) {
			foreach ($propDesc->value as $val) {
				$this->processProperty($val);
			}
		} else {
			$propDesc->name = $this->properties->evalPropertyString($propDesc->name);
			$propDesc->value = $this->properties->evalPropertyString($propDesc->value);
		}
	}

	public function setProperties(Properties $properties) {
		$this->properties = $properties;
	}
}

?>